<template>
  <view>
    <uv-popup closeable mode="center" ref="popup" @change="change">
      <view class="dialog">
        <view style="font-size: 16px">录入报产数</view>
        <uv-form labelPosition="left" :model="model1" :rules="rules" ref="form">
          <uv-form-item :labelWidth="80" label="部门名称" borderBottom @click="showUser">
            <uv-input disabled disabledColor="#ffffff" v-model="userInfo.deptName" border="none"> </uv-input>
          </uv-form-item>

          <uv-form-item :labelWidth="80" label="选择员工" borderBottom @click="showUser">
            <uv-input disabled disabledColor="#ffffff" v-model="userInfo.workName" border="none"> </uv-input>
          </uv-form-item>
          <uv-form-item :labelWidth="80" label="报产数" borderBottom>
            <uv-input disabled disabledColor="#ffffff" v-model="serialNumber" border="none"> </uv-input>
          </uv-form-item>
        </uv-form>
      </view>
      <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scroll="scroll">
        <uni-table border stripe emptyText="暂无更多数据">
          <!-- 表头行 -->
          <uni-tr>
            <uni-th :width="50" align="center">指令</uni-th>
            <uni-th :width="50" align="center">序号</uni-th>
            <uni-th :width="50" align="center">工序名称</uni-th>
            <uni-th :width="50" align="center">数量</uni-th>
            <uni-th v-show="tableData[0].addShow" :width="50" align="center">修改数量</uni-th>
          </uni-tr>
          <!-- 表格数据行 -->
          <uni-tr v-for="item in tableData">
            <uni-td>{{ item.lotNo }}</uni-td>
            <uni-td>{{ item.seqNo }}</uni-td>
            <uni-td>{{ item.processName }}</uni-td>
            <uni-td>{{ item.qty3 }}</uni-td>
            <uni-td v-show="item.addShow">
              <uv-input v-model="item.qty4" border="none"> </uv-input>
            </uni-td>
          </uni-tr>
        </uni-table>
      </scroll-view>
      <uv-button class="btn" type="primary" text="确定" @click="search"></uv-button>
    </uv-popup>

    <user :show="userDialogShow" :searchObj="searchObj"></user>
    <uv-notify ref="notify" type="error"></uv-notify>
    <uv-notify ref="notify2" type="success"></uv-notify>
  </view>
</template>

<script>
import user from "@/components/user/user.vue";
export default {
  name: "inputNum",
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    tableData: {
      type: Array,
      default: [],
    },
    searchObj: {
      type: Object,
      default: {},
    },
    scrollTop: 0,
    old: {
      scrollTop: 0,
    },
  },
  computed: {
    serialNumber() {
      let sum = 0;
      for (var i = 0; i < this.tableData.length; i++) {
        sum = sum + Number(this.tableData[i].qty3);
      }
      return sum;
    },
  },
  data() {
    return {
      userDialogShow: false,
      user: "",
      userInfo: {},
    };
  },
  methods: {
    scroll: function (e) {
      // console.log(e)
      this.old.scrollTop = e.detail.scrollTop;
    },
    showUser() {
      console.log(this.userDialogShow);
      this.userDialogShow = !this.userDialogShow;
    },
    // 点击确定按钮
    search() {
      // 判断是多选合并还是单行修改
      if (this.tableData[0].addShow === true) {
        uni.request({
          url: "/kl/pad/stitchProductionReport/reportProcessByDefineQty",
          header: {
            Authorization: uni.getStorageSync("token"), //自定义请求头信息
          },
          data: {
            stitchRequest: this.$props.tableData[0],
            qty4: this.tableData[0].qty4,
            ...this.userInfo,
          },
          method: "POST",
          success: (res) => {
            if (res.data.code === 200) {
              uni.$emit("refresh", true);
              this.$refs.notify2.show({
                message: res.data.message,
              });
              this.$refs.popup.close();
            } else {
              this.$refs.notify.show({
                message: res.data.message,
              });
            }
          },
        });
      } else {
        uni.request({
          url: "/kl/pad/stitchProductionReport/batchReportProcess",
          header: {
            Authorization: uni.getStorageSync("token"), //自定义请求头信息
          },
          data: {
            list: this.$props.tableData,
            ...this.userInfo,
          },
          method: "POST",
          success: (res) => {
            console.log(res);
            console.log({
              list: this.$props.tableData,
              ...this.userInfo,
            });
            if (res.data.code === 200) {
              uni.$emit("refresh", true);
              this.$refs.notify2.show({
                message: res.data.message,
              });
              this.$refs.popup.close();
            } else {
              this.$refs.notify.show({
                message: res.data.message,
              });
            }
          },
        });
      }
    },
  },
  watch: {
    show(newVal, oldVal) {
      console.log(newVal);
      this.$refs.popup.open("cneter");
      uni.$on("userInfo", (data) => {
        this.userInfo = JSON.parse(data);
        console.log(this.userInfo);
      });
    },
  },
};
</script>

<style>
.dialog {
  padding: 20rpx 30rpx 30rpx;
}

.btn {
  margin: 30rpx;
}
.scroll-Y {
  height: 50vh;
}

.scroll-view_H {
  white-space: nowrap;
  width: 100%;
}

.scroll-view-item {
  height: 50vh;
  line-height: 50vh;
  text-align: center;
  font-size: 36rpx;
}

.scroll-view-item_H {
  display: inline-block;
  width: 100%;
  height: 50vh;
  line-height: 50vh;
  text-align: center;
  font-size: 36rpx;
}
</style>
